function send_dianping( dp_star, dp_text, party_email )
{   
	var dp_cont = encodeURIComponent( $.trim(dp_text) );
	var ser_result;
	$.ajax({
		type:"post",
		async : false,
		url:"server.php",
		data:"act=send_dianping&star="+dp_star+"&content="+dp_cont+"&party_email="+party_email,
		beforeSend: function(XMLHttpRequest){
		
		},
		success: function(data){

		  ser_result = data;
		}
		});
	
	return ser_result;
}

function get_dianping( ul_for_li, party_email, page )
{
	$.ajax({
		type:"get",
		async : true,
		url:"server.php",
		data:"act=get_dianping&party_email="+party_email+"&page="+page,
		beforeSend: function(XMLHttpRequest){
		  loading_gif = $('<img src="./images/loading17.gif" alt="请等待" style="margin: 70px 0px 0px 300px;" />');
		  ul_for_li.append( loading_gif );
		},
		success: function(data){
		  
		  //先删除loading图片
		  ul_for_li.empty();

		  //data即为ajax的返回值，json格式的点评内容
		  render_dianping_list( ul_for_li, data, page );
		  
		}
		});
}

function render_dianping_list( ul_for_li, dianping_json, page )
{
	//得到json格式的点评数据dianping_json
	/*json格式的点评数据举例如下：
	  {"dp_info":[{"starraty":"5","dianping_txt":"你好","dianping_time":"2012-12-24 15:59:16"},
	              {"starraty":"5","dianping_txt":"555","dianping_time":"2012-12-24 16:13:37"},
				  {"starraty":"4","dianping_txt":"5555","dianping_time":"2012-12-24 16:13:48"},
				  {"starraty":"5","dianping_txt":"gd fdg","dianping_time":"2012-12-24 16:15:20"},
				  {"starraty":"4","dianping_txt":"oo","dianping_time":"2012-12-24 16:15:39"}
				 ],
		"totalpage":1
	  }
	  如果没有任何点评，返回样式如下：
	  {"dp_info":[],"totalpage":1}
	*/
	var dianping_obj = eval('(' + dianping_json + ')'); //将 json转成obj

	//说明没有取到任何点评
	if( 0 == dianping_obj.dp_info.length )
	{
	    var notice = $('<p style="color:#888; float:left; margin-left:10px; margin-top:10px;">该商户暂无点评。<br />点评和打分都将是其他网友的参考依据，并影响该商户评分。<br />现在就去点评抢沙发吧。</p>');
	    ul_for_li.append(notice);
		return ;
	}
	//解析obj，得到若干li，每个li是一封点评信息。最少1封，最多10封。因为一页设定为最多10封。
	for(var i=0; i<dianping_obj.dp_info.length; i++)
	{
		var starraty = dianping_obj.dp_info[i].starraty;
		var dianping_txt = dianping_obj.dp_info[i].dianping_txt;
		//var uIP = dianping_obj.dp_info[i].uIP;
		var dianping_time = dianping_obj.dp_info[i].dianping_time;

		var img = "http://timg.ddmapimg.com/user/bbshead/small/2012-03/20120321183750790.jpg";
		//var uname = "临时网友  " + uIP;
		var uname = "热心网友";
		
		//先生成一个li的各各节点。再组合。
		dianping_li = $("<li></li>");
		
		li_img = $('<img width="48" height="48" alt="" />');
		li_img.attr("src", img);

		div_dp_li_right = $('<div class="dp_li_right"></div>');

		div_dp_uname = $('<div class="dp_uname"><span></span></div>');
		div_dp_uname.children("span").text( uname );

		div_dp_star = $('<div class="dp_star"><span></span></div>');
		div_dp_star.children("span").addClass( "star"+starraty );

		div_dp_cont = $('<div class="dp_cont"><span></span></div>');
		div_dp_cont.children("span").text( dianping_txt );

		div_dp_time = $('<div class="dp_time"><span></span></div>');
		div_dp_time.children("span").text( dianping_time );

		//组合
		dianping_li.append(li_img);
		dianping_li.append(div_dp_li_right);

		div_dp_li_right.append(div_dp_uname);
		div_dp_li_right.append(div_dp_star);
		div_dp_li_right.append(div_dp_cont);
		div_dp_li_right.append(div_dp_time);
		
		ul_for_li.append(dianping_li);
	}
	
	//下面根据当前页数page，以及总页数dianping_obj.totalpage，来渲染出页面的点击按钮。
	$(".pagenum ul").empty();
	create_page_button( page, dianping_obj.totalpage );
	
	return ;

}

function create_page_button( currentpage, totalpage )
{
    if( totalpage >= 1 ) //说明至少有1页，需要渲染页面按钮。
	{
		firstpage = 1;
		lastpage = totalpage
		
		if(currentpage > lastpage)
			currentpage = lastpage;  //不让当前页超过最大页
		else if(currentpage<firstpage)
			currentpage = firstpage; //不让当前页小于第一页
		
		hasFirstPage = true;
		hasLastPage = true;
		hasPrePage = true;
		hasNextPage =true;
		
		pagenum = '';
		
		for(i=4; i>=1; i--)
		{
			leftpage = currentpage-0-i; //-0是为了转换成数字类型。
			if( leftpage <= 0 )
			{
				continue;
			}
			if( leftpage == 1 )
				hasFirstPage = false;
				
			pagenum = pagenum+'<a href="javascript:void(0);" onclick="jump_to_page('+leftpage+');"><li class="unhover">'+leftpage+'</li></a>';
		}
		
		pagenum = pagenum+'<li class="selected">'+currentpage+'</li>';
	
		for( i=1; i<=4; i++ )
		{
			rightpage = currentpage-0+i; //-0是为了转换成数字类型。
			if( rightpage > lastpage )
				break;
				
			if( rightpage == lastpage )
				hasLastPage = false;
			
			pagenum = pagenum+'<a href="javascript:void(0);" onclick="jump_to_page('+rightpage+');"><li class="unhover">'+rightpage+'</li></a>';
		}
		
		if( currentpage == 1 )
		{
			hasFirstPage = false;
			hasPrePage = false
		}
			
		if( currentpage == lastpage )
		{
			hasLastPage = false;
			hasNextPage = false;
		}

		if( hasFirstPage == true )
		{
			pagenum = '<a href="javascript:void(0);" onclick="jump_to_page('+firstpage+');"><li class="unhover" style="width:44px;">首页</li></a>'+pagenum;
		}

		if( hasLastPage == true )
		{
			pagenum = pagenum+'<a href="javascript:void(0);" onclick="jump_to_page('+lastpage+');"><li class="unhover" style="width:44px;">尾页</li></a>';
		}

		if( hasPrePage == true )
		{
			pagenum = '<a href="javascript:void(0);" onclick="jump_to_page('+(currentpage-0-1)+');"><li class="unhover" style="width:44px;">上一页</li></a>'+pagenum;
		}

		if( hasNextPage ==true )
		{
			pagenum = pagenum+'<a href="javascript:void(0);" onclick="jump_to_page('+(currentpage-0+1)+');"><li class="unhover" style="width:44px;">下一页</li></a>';
		}

		$(".pagenum ul").html( pagenum );
	
	}

}